package serviceUser

import (
	"context"
	"mxshop/app/mxshop_api/admin/internal/data"
	dtoUser "mxshop/app/mxshop_api/admin/internal/domain/dto/user"
	srvUser "mxshop/app/mxshop_api/admin/internal/service/user"
	metav1 "mxshop/gmicro/pkg/common/meta/v1"
	"mxshop/pkg/options"
)

type userService struct {
	data    data.DataFactory
	jwtOpts *options.JwtOptions
}

func (us *userService) List(ctx context.Context, orderby []string, opts metav1.ListMeta) (*dtoUser.UserDTOList, error) {
	var userList dtoUser.UserDTOList

	rsp, err := us.data.User().List(ctx, orderby, opts)
	if err != nil {
		return nil, err
	}

	for _, user := range rsp.Items {
		userList.Items = append(userList.Items, &dtoUser.UserDTO{
			UserDO: *user,
		})
	}
	userList.TotalCount = rsp.TotalCount

	return &userList, nil
}

func NewUserService(data data.DataFactory) srvUser.UserSrv {
	return &userService{
		data: data,
	}
}
